home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / delall.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-04  |  2.1 KB  |  78 lines

  1. ;void  delete_all(strg,ch,position);
  2. ;  unsigned char   *strg,ch,position;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _delete_all
  10. _delete_all proc near
  11.     mov  _error_code,1    ;assume an error will occur
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push si            ;
  16.     push ds            ;save DS
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    cmp  _memory_model,2    ;data near or far?
  22.     jb   L0            ;jump if near
  23.     lds  si,dword ptr[bp+4] ;DS:SI pts to the string
  24.     inc  bp            ;add 2 to BP since dword ptr
  25.     inc  bp            ;
  26.     jmp  short L1        ;
  27. L0:    mov  si,[bp+4]        ;NEAR case
  28. L1:    mov  ax,ds        ;ES = DS
  29.     mov  es,ax        ;
  30.     sub  cx,cx        ;
  31.     mov  al,[bp+6]        ;get the search char
  32.     mov  cl,[bp+8]        ;get starting position
  33.     inc  cx            ;count from 1
  34.     mov  dx,cx        ;keep a copy
  35. L2:    cmp  byte ptr[si],0    ;move si to starting pos
  36.     je   L10        ;quit if start is outside string
  37.     inc  si            ;
  38.     loop L2            ;loop
  39.     cmp  [si-1],al        ;search char at position?
  40.     jne  L10        ;quit if not
  41.     mov  di,si        ;copy ptr
  42.     mov  cx,dx        ;search left for character
  43. L3:    dec  di            ;
  44.     cmp  byte ptr[di],al    ;search char?
  45.     jne  L4            ;quit loop if not
  46.     loop L3            ;loop
  47.     dec  di            ;cancel effect of next line
  48. L4:    inc  di            ;
  49. L5:    cmp  byte ptr[si],0    ;SI at end of string?
  50.     je   L6            ;nothing to search for if so
  51.     inc  si            ;begin search to right
  52.     mov  ah,[si]        ;get a char
  53.     cmp  ah,0        ;end of string?
  54.     jne  L7            ;jump ahead if not
  55. L6:    mov  byte ptr[di],0    ;all eliminated to right
  56.     jmp  short L9        ;set null and quit
  57. L7:    cmp  ah,al        ;search char?
  58.     je   L5            ;loop if so
  59.     cld            ;now transfer down high end of string
  60. L8:    lodsb            ;get a char
  61.     stosb            ;shift it
  62.     cmp  al,0        ;end of string?
  63.     jne  L8            ;loop till end
  64. L9:    pop  ds            ;restore DS
  65.     dec  _error_code    ;no error
  66.     jmp  short L11        ;jump ahead
  67. L10:    pop  ds            ;error case
  68. L11:    pop  si            ;
  69.     pop  di            ;
  70.     pop  bp            ;
  71.     cmp  _memory_model,0    ;quit
  72.     jle  quit        ;
  73.     db   0CBh        ;RET far
  74. quit:    ret            ;RET near
  75. _delete_all ENDP
  76. _TEXT    ENDS
  77.     END
  78.